﻿var adminfs = {};

adminfs.generateTable = function (lstSanPham) {

var html = '<div class="ContentPart">' + 
'<h3 class="ContentPartHeader" id="tableHeader">Danh sách Sản phẩm</h3>' +
'<table class="tableQuanLy" border="0" cellpadding="0" cellspacing="0">' +
	'<thead align="center">'+
	'	<tr>'+
	'		<th>STT</th>'+
	'		<th>Mã SP</th>'+
	'		<th>Tên SP</th>'+
	'		<th>Loại</th>'+
	'		<th>Nhà SX</th>'+
	'		<th>Xuất xứ</th>'+
	'		<th>Đơn giá (VNĐ)</th>'+
	'		<th>Ngày bán</th>'+
	'		<th>Đã xóa</th>'+
	'	</tr>'+
	'</thead>'+
	'<tbody>';

	$.each(lstSanPham, function (index, value) {
		/*'<c:forEach var="i" begin="0" end="${requestScope.listSanPham.size()-1}">'+
			'<c:choose>'+
				'<c:when test="${(i + 1) % 2 == 1 }">'+
					'<tr class="rowLe">'+
				'</c:when>'+
				'<c:otherwise>'+
					'<tr class="rowChan">'+
				'</c:otherwise>'+
			'</c:choose>'+*/
		if (index % 2 == 0)
			html = html + '<tr class="rowChan">';
		else
			html = html + '<tr class="rowLe">';
		
			html = html + '<td width="4%">${i + 1}</td>'+
			'<td width="8%"><a href="#">' + value.getMasanpham() + '</a></td>'+
			'<td><a href="#">' + value.getTensanpham() + '</a></td>'+
			'<td width="10%">' + value.getLoaisanpham().getTenloaisanpham() + '</a></td>'+
			'<td width="15%">' + value.getNhasanxuat().getTennhansanxuat() + '</td>'+
			'<td width="10%">' + value.getXuatxu() + '</td>'+
			'<td width="12%" align="right"><font color="#FF0000">'+
			'		<fmt:formatNumber type="number"	value="'+ value.getGiaban() + '" groupingUsed="true" />'+
			'</font></td>'+
			'<td width="10%">' + value.getNgaynhansanpham() + '</td>'+
			'<td width="3%" align="center">';
			if (value.getDaxoa() == true)
				html =html + 'Duyệt';
			else
				html =html + 'Chưa';
			html =html + '</td>'+
			'</tr>';
	});
		/*'</c:forEach>'+*/
	html =html + 
	'</tbody>'+
'</table>'+
'</div>';

	var divContent = $("#tableDanhSach");
    $(divContent).empty();
    divContent.innerHTML = html;
};



adminfs.generateTable = function () {

    //alert("GenFriend");
    var ulResult = $("#friendList");
    $(ulResult).attr("class", "ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons");
    $(ulResult).attr("role", "menu");
    $(ulResult).attr("tabindex", "0");
    $(ulResult).attr("aria-activedescendant", "ui-id-5");
    $(ulResult).empty();

    $.each(lstFriend, function (index, value) {
        //------------
        var li_friendItem = document.createElement('li');
        $(li_friendItem).attr("class", "ui-menu-item");
        $(li_friendItem).attr("role", "presentation");

        var a_link = document.createElement('a');
        $(a_link).attr("id", "ui-id-" + index + 1);
        $(a_link).attr("class", "ui-corner-all");
        $(a_link).attr('onclick',
            'return cchat.addFriendTab("' + value.username + '")');
        $(a_link).attr("tabindex", "-1");
        $(a_link).attr("role", "menuitem");

        var span_icon = document.createElement('span');
        //$(span_icon).addClass("iconStatus");
        //$(span_icon).addClass("ui-icon");
        //$(span_icon).attr("id", "iconFriend-" + value.username);

        var img_icon = document.createElement('img');
        $(img_icon).addClass("iconStatus");
        $(img_icon).addClass("ui-icon");
        $(img_icon).attr("id", "iconFriend-" + value.username);
        //$(img_icon).attr("src", value.hinhdaidien);
        span_icon.appendChild(img_icon);

        var span_item = document.createElement('span');
        $(span_item).addClass("menuItemName");
        $(span_item).attr("id", "itemFriend-" + value.username);

        var font_item = document.createElement('font');
        $(font_item).attr("color", "#AAAAAA");
        font_item.innerHTML = value.hoten + " (" + value.username + ")";

        span_item.appendChild(font_item);

        //a_link.innerHTML = value.hoten;
        a_link.appendChild(span_icon);
        a_link.appendChild(span_item);

        li_friendItem.appendChild(a_link);

        ulResult.append(li_friendItem);
    });


    $.each(lstFriend, function (index, value) {
        $(value).attr('src', cchat.getImageOfUser(value.username, "iconFriend-" + value.username));
        //alert("complete " + value.username);
    });
};
